#include "base/SpeculativeCounter.h"

NEW_DELETE_OPERATORS_CPP(SpeculativeCounter,1000);

SpeculativeCounter::SpeculativeCounter (const char* _outName,
                                        const char* _outRollbackName) 
    : Counter(_outName)
{
    outputRollbackName = _outRollbackName;
    valueSpeculative = 0;
    valueRollback = 0;
}

SpeculativeCounter::~SpeculativeCounter ()
{
    // nothing
}

void SpeculativeCounter::increment (bool isSpeculative, uint amount)
{
    if (isSpeculative) {
        valueSpeculative += amount;
    } else {
        value += amount;
    }
}

void SpeculativeCounter::commit ()
{
    value += valueSpeculative;
    valueSpeculative = 0;
}

void SpeculativeCounter::rollback ()
{
    valueRollback += valueSpeculative;
    valueSpeculative = 0;
}

void SpeculativeCounter::clear ()
{
    valueSpeculative = 0;
    valueRollback = 0;
    Counter::clear();
}
